package com.hkfg.dao;

import com.hkfg.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserDao {


    /**
     * 根据用户名喝密码查询用户对象
     * @param username
     * @param password
     * @return
     */
    @Select("select * from b_user where username = #{username} and password = #{password};")
    User select(@Param("username") String username, @Param("password") String password);


    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from b_user where username = #{username};")
    User selectByUsername(String username);


    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into b_user values(null, #{username}, #{password}, #{description}, null, null, null, #{emotion}, null, null, null);")
    void add(User user);

    /**
     * 根据id查找返回User
     * @param id
     * @return
     */
    @Select("select * from b_user where id = #{id};")
    User selectById(int id);

    /**
     * 更新欢迎语
     * @param id
     * @param description
     * @return
     */
    @Update("update b_user set description = #{description} where id = #{id};")
    int modifyWelcome(@Param("id") int id, @Param("description") String description);


}
